home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-09 | 4.8 KB | 165 lines | [TEXT/CWIE] |
- // Simple framework for Macintosh sample code
- //
- // David Hayward and Nick Thompson
- // Developer Technical Support
- // AppleLink: DEVSUPPORT
- //
- // Copyrite 1995, Apple Computer,Inc
- //
- // This file contains the QuickDraw GX printing sample code, we want to have
- // GX analogs for all the classic printing functions, and we will have some
- // additional routines in here. This is pretty much based on the recipes in
- // the book Inside Macintosh QuickDraw GX: Programmers Overview
- //
- // 10/4/94 david first cut
-
-
- #include <Gestalt.h>
- #include <CodeFragments.h>
- #include <GXTypes.h>
- #include <GXGraphics.h>
- #include <GXEnvironment.h>
- #include <GXPrinting.h>
- #include <GXErrors.h>
- #include "GraphicsLibraries.h"
-
- #include "gxGlobals.h"
- #include "gxUtils.h"
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE GLOBALS
- |**| ==============================================================================
- \**/
- OSErr gQDGX_present_err = 1;
- OSErr gQDGX_available_err = 1;
- OSErr gQDGX_initialized_err = 1;
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- QDGX_present
- *------------------------------------------------------------------------------*
- This function returns noErr if QuickDraw GX graphics and typography are present
- (i.e passes gestalt) and returns an error otherwise.
- It also sets the global gQDGX_present_err based on the result.
- \*------------------------------------------------------------------------------*/
- OSErr QDGX_present ( void )
- {
- OSErr err;
- long response;
-
- if ( gQDGX_present_err==noErr )
- return noErr ;
-
- err = Gestalt(gestaltGraphicsVersion, &response) ;
-
- gQDGX_present_err = err;
- return err;
- }
-
-
- /*------------------------------------------------------------------------------*\
- QDGX_available
- *------------------------------------------------------------------------------*
- This function returns noErr if QuickDraw GX graphics and typography are available
- (i.e present and initialized) to the application and returns an error otherwise.
- It also sets the global gQDGX_available_err based on the return value.
- \*------------------------------------------------------------------------------*/
- OSErr QDGX_available ( void )
- {
- OSErr err;
-
- if ( gQDGX_available_err==noErr )
- return noErr;
-
- err = QDGX_present();
- if ( !err )
- err = QDGX_initialize();
-
- gQDGX_available_err = err;
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- QDGX_initialize
- *------------------------------------------------------------------------------*
- This function initializes all the GX stuff.
- It should be called early in the application.
- \*------------------------------------------------------------------------------*/
- OSErr QDGX_initialize ( void )
- {
- OSErr err;
-
- if ( !gQDGX_initialized_err )
- return noErr;
-
- err = QDGX_present();
- if ( !err )
- {
- gQDGXClient = GXNewGraphicsClient(nil,
- gQDGXGraphicsHeapSize * 1024L,
- (gxClientAttribute)0L) ;
- err = GXGetGraphicsError( nil ) ;
- }
-
- if ( !err )
- {
- #ifdef QDGXDebugging
- // If gDebugging = TRUE, you will receive graphics library errors & notices will be posted.
- // This functionality will only work with the "debugging" version of QuickDraw GX. If you
- // don't have the debugging version installed, these functions will not work.
- SetGraphicsLibraryErrors() ;
- SetGraphicsLibraryNotices() ;
- #endif
-
- #ifdef QDGXValidation
- // Set gQDGXValidation to TRUE if you want run-time validation. As you increase the amount
- // of validation, The drawing speed will SLOW down due to all of the internal checking.
- // gxPublicValidation will check parameters to public routines. For additional details
- // regarding the various levels of validation, see "Inside Macintosh: QuickDraw GX
- // Environment and Utilties."
- GXSetValidation( gxPublicValidation ) ;
- #endif
- }
-
- if ( !err )
- { // initialise the gx heap
- GXEnterGraphics() ;
-
- // check we were ok - no errors
- err = GXGetGraphicsError( nil ) ;
- if (err)
- GXDisposeGraphicsClient( gQDGXClient ) ;
- }
-
- gQDGX_initialized_err = err;
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- DisposeGXStuff
- *------------------------------------------------------------------------------*
- This function disposes all the GX stuff.
- It should be called before the application exits.
- \*------------------------------------------------------------------------------*/
- void DisposeGXStuff ( void )
- {
- if( !gQDGX_initialized_err )
- {
- GXExitGraphics() ;
- GXDisposeGraphicsClient( gQDGXClient ) ;
- gQDGX_initialized_err = 1;
- }
- }
-
-